﻿#ifndef __AVOID_BW_CONTROL_IMGBUTTON_HEAD_FILE_INCXLUDED__
#define __AVOID_BW_CONTROL_IMGBUTTON_HEAD_FILE_INCXLUDED__
#include "ctlImage.h"
#include "interface/IDrag.h"
#include "interface/IUserDraw.h"

namespace swui
{
#pragma warning(push)
#pragma warning(disable:4250)
	class ctlImageButton : virtual public ctlRoot,
		public IDrag, public IUserDraw
	{
	public:
		static const ctlControlType uniqueType = ctlControlType::ctlImageButton;
	public:
		virtual ~ctlImageButton() { destroy(); }
		bool create(ctlRoot* parent, ctlRect rect);
	public:
		void setImage(unsigned leave, unsigned stay,
			unsigned down, unsigned disenabled);
		void setImage(ctlQuadColor<unsigned>);
		ctlQuadColor<unsigned> getImageIndex();
		ctlQuadColor<std::shared_ptr<ctlImage>> getImage();
		void setLeaveImage(unsigned index);
		void setStayImage(unsigned index);
		void setDownImage(unsigned index);
		void setDisenabledImage(unsigned index);
		std::shared_ptr<ctlImage> getLeaveImage();
		std::shared_ptr<ctlImage> getStayImage();
		std::shared_ptr<ctlImage> getDownImage();
		std::shared_ptr<ctlImage> getDisenabledImage();
	public:
		//遮罩颜色也不属于控件（32 位或 24 位）
		void setMaskColor(ctlColor mask);
		ctlColor getMaskColor();
		bool hasMask();
		void enableMask(bool);
		/* 设置判断鼠标在控件上的方法（仅 32 位图像）
		 * 若某个点的像素值透明度小于或等于下面的值
		 * 那么认为这个点不在控件，否则在这个点在控件
		 * 判断是根据 leave 的图像，并与 setImageAlpha 无关 */
		void setJudgeAlpha(unsigned char);
		unsigned char getJudgeAlpha();
		void setImageAlpha(ctlQuadColor<unsigned char>);
		void setImageAlpha(unsigned char leave, unsigned char stay,
			unsigned char down, unsigned char disenabled);
		ctlQuadColor<unsigned char> getImageAlpha();
	public:
		//返回是否缩放图像
		bool isScaleImage();
		//设置是否缩放图像
		void setScaleImage(bool);
	public:
		//设置按钮是否有选中和未选中区别
		void enableSelected(bool);
		bool isSelectedEnabled();
		bool isSelected();
		void setSelected(bool);
		void setSelectedImage(ctlQuadColor<unsigned> inedx);
		ctlQuadColor<std::shared_ptr<ctlImage>> getSelectedImage();
		ctlQuadColor<unsigned> getSelectedImageIndex();
		void setSelectedImageAlpha(ctlQuadColor<unsigned char>);
		ctlQuadColor<unsigned char> getSelectedImageAlpha();
	protected:
		virtual void _redraw_(_ctlInterior::drawInfo*);
		virtual void _mouse_event_(ctlMouseEvent*);
		virtual bool _judge_point_(ctlPoint);
	private:
		ctlQuadColor<unsigned> _image_button_index;
		ctlQuadColor<unsigned char> _image_button_alpha;
		unsigned char _image_button_judge_alpha;
		bool _image_button_scale;
		ctlColor _image_button_mask_color;
		bool _image_button_is_mask;
		bool _image_selected_enable;
		bool _image_is_selected;
		ctlQuadColor<unsigned> _image_selected_index;
		ctlQuadColor<unsigned char> _image_selected_alpha;
	};
#pragma warning(pop)
}

#endif
